<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/lib/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/css/public.css" media="all">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/css/wp.css" media="all">

    <style>
        .item {
            height: 50px;
            border-bottom: 1px solid #dddddd;
            line-height: 50px;
        }

        .key {
            float: left;
        }

        .value {
            float: right;
        }

        .input-block {
            margin-right: 50px;
        }

        .unit {
            position: absolute;
            right: 0px;
            top: 0px;
            right: -30px;
            line-height: 40px;
        }
    </style>
</head>
<body>
<div id="container" class="layuimini-container">
    <div class="layuimini-main">

        <h2 class="wp-module-title">兑换申请</h2>
        <div class="wp-module-box wp-module-border">

            <div class="item">
                <div class="key">转入币种</div>
                <div class="value" v-text="turnMoneyTypeName">USDT</div>
            </div>

            <div class="item">
                <div class="key">转入金额</div>
                <div class="value"><span v-text="moneyAmount">200</span>&nbsp;<span v-text="turnMoneyTypeName"></span></div>
            </div>

            <div class="item">
                <div class="key">申请时间</div>
                <div class="value" v-text="createDate">2020.01.11</div>
            </div>

        </div>

        <div class="wp-module-box" style="margin-top: 15px">
            <h3><b>处理信息</b></h3>
            <form id="myform" class="layui-form" action="" lay-filter="example" style="padding-top: 10px;">
                <div class="item" style="border: none">
                    <div class="key">兑换币种</div>
                    <div class="value" v-text="exchangeMoneyTypeName">SHQC</div>
                </div>

                <div class="layui-form-item" style="margin-left: -40px;height: 30px;">
                    <label class="layui-form-label">融资轮次</label>
                    <div class="layui-input-block">
                        <select id="converType" v-model="converType" lay-filter="converType" lay-verify="emptyCheck">
                            <option value="1000" selected="">天使轮</option>
                            <option value="2000">基石轮</option>
                        </select>
                    </div>
                </div>

                <div class="item" style="border: none">
                    <div class="key">可兑换数量</div>
                    <div class="value"><span v-text="exchangeAmount">500</span> <span v-text="exchangeMoneyTypeName">SHQC</span></div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block" style="margin: auto;text-align: center;">
                        <button type="submit" style="width: 120px;" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="data-submit-btn">
                            提交
                        </button>
                    </div>
                </div>
            </form>
        </div>

    </div>
</div>

<script src="/wpui-admin/wp-ewallet-admin/static/js/jquery-3.4.1.min.js"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/lib/layui/layui.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/module/index/config.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/js/vue.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/js/vue-i18n.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp-i18n.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp-project.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            element = layui.element;

        var vm = new Vue({
            el: '#container',
            i18n: wp.i18n(),
            data: {
                name: '张三',
                reqOrderId: "",
                turnMoneyType: "",
                moneyAmount: "",
                exchangeMoneyType: "",
                reqType: "",
                orderStatus: "",
                walletAddress: "",
                accountId: "",
                remark: "",
                reqTypeName: "",
                operResult: "",
                operUser: "",
                operRemark: "",
                exchangeRate: "",
                exchangeAmount: "",
                converType: "",
                turnMoneyTypeName: "",
                exchangeMoneyTypeName: "",
                createDate:''
            },
            mounted: function () {
                form.render();
                this.submitEvent();
                this.selectLcEvent();
                this.getExchangeMoneyReqOrderById();
            },
            methods: {
                selectLcEvent:function(val){
                    var that = this;
                    form.on('select(converType)', function(data){
                        that.converType = data.value;
                        that.exchange();
                    });
                },
                submitEvent: function () {
                    var that = this;
                    // 需要的时候自定义验证规则
                    form.verify({
                        emptyCheck:function(value){
                            if(!value){
                                return '不能为空';
                            }
                        }
                    });

                    // 监听提交操作
                    form.on('submit(data-submit-btn)', function (data) {
                        layer.confirm("确认同意兑换申请?", {title:"提示信息",icon:0}, function(index){
                            layer.close(index);
                            var loading = wp.loading();
                            wp.httpPost({
                                url: wp.url("/wp/ewallet/wallet/exchangeMoney/handleExchangeMoneyOrder"),
                                data: {
                                    reqOrderId: that.reqOrderId,
                                    converType: that.converType
                                },
                                success: function (data) {
                                    wp.closeLoading(loading);
                                    layer.msg('处理完成');

                                    // 关闭窗口，刷新父窗口列表
                                    window.walletApplyVm.reloadGrid();
                                    window.close();
                                },
                                failure:function(data){
                                    wp.closeLoading(loading);
                                    if(data.code == '1'){
                                        layer.msg('订单不存在或者订单状态不是待处理');
                                        return;
                                    }

                                    if(data.code == '2'){
                                        layer.msg('兑换条件异常');
                                        return;
                                    }
                                }
                            });
                        });
                        return false;
                    });
                },
                getExchangeMoneyReqOrderById: function () {
                    var data = window.data;
                    var that = this;
                    wp.httpGet({
                        url: wp.url("/wp/ewallet/wallet/reqOrder/id/exchangeMoney"),
                        data: {
                            orderId: data.reqOrderId
                        },
                        success: function (data) {
                            console.log(JSON.stringify(data.dataBody));
                            $.extend(that,data.dataBody);
                            that.exchange();
                            that.$nextTick(function(){
                                // 赋值完后再次渲染表单下拉框方可正常选中
                                form.render();
                            });
                        }
                    })
                },
                exchange:function(){
                    var that = this;
                    if(!that.moneyAmount){
                        return;
                    }

                    wp.httpPost({
                        url:wp.url('/wp/ewallet/wallet/exchangeMoney/calculateUsdtToShqc'),
                        data:{
                            exchangeAmount:that.moneyAmount,
                            converType: that.converType
                        },
                        success:function(data){
                            that.exchangeAmount = data.dataBody;
                        }
                    });
                },
            }
        });

    });
</script>

</body>
</html>